# coding:utf-8
"""
description:Forget password功能
"""
import os

from common import Base_Page
from appium.webdriver.common import mobileby
from common.Get_Yaml import get_yaml
from config.GlobalParameter import TEST_Element_YAML

testData = get_yaml(os.path.join(TEST_Element_YAML, 'ForgetPwd.yaml'))


class forgetpwd_page(Base_Page.Base_page):
    by = mobileby.MobileBy()

    linkForgetPwd_loc = (by.ID, testData.get_elementInfo(0))

    def click_linkForgetPwd(self):
        """点击 login页面中的Forget Password link"""
        self.find_element(*self.linkForgetPwd_loc).click()

    def func_inputEmail(self, getResetemail, message):
        """
        获取要修改email的code
        :param getResetemail: 要修改密码的email
        :param message: 断言提示内容
        :return:
        """
        self.input_ResetPassword(getResetemail)
        self.click_btnResetEmail()
        return self.find_toast(message)

    def func_ForgetPwd(self, emailcode, NewPassword, NewPasswordCfm,message):
        """
        忘记密码
        :param emailcode: 获取要修改email收到的code
        :param NewPassword: 新密码
        :param NewPasswordCfm: 新密码确认
        :param message:
        :return:
        """
        self.input_ResetPassword(emailcode)
        self.input_ResetPasswordNewPassword(NewPassword)
        self.input_ResetPasswordNewPasswordCfm(NewPasswordCfm)
        self.click_btnResetCode()
        return self.find_toast(message)

    """Forget Password pop"""
    ivClosePopup_loc = (by.ID, testData.get_elementInfo(1))
    etResetPassword_loc = (by.ID, testData.get_elementInfo(2))
    btnResetEmail_loc = (by.ID, testData.get_elementInfo(3))

    def input_ResetPassword(self, ResetPassword):
        """Forget password:输入reset password
        Reset Password：输入reset password code"""
        self.send_keys(ResetPassword, self.find_element(*self.etResetPassword_loc))

    def click_ClosePopup(self):
        """点击x ClosePopup按钮关闭"""
        self.find_element(*self.ivClosePopup_loc).click()

    def click_btnResetEmail(self):
        """点击Next 按钮"""
        self.find_element(*self.btnResetEmail_loc).click()

    def assertVisible_Forgetnext(self):
        """判断next 按钮是否存在"""
        return self.assertVisible(*self.btnResetEmail_loc)

    def func_forgetPwdPop(self):
        """
        点击forget pwd链接，打开
        :return:
        """
        self.click_linkForgetPwd()
        return self.assertVisible_Forgetnext()

    """Reset Password pop"""
    etResetPasswordNewPassword_loc = (by.ID, testData.get_elementInfo(4))
    etResetPasswordNewPasswordCfm_loc = (by.ID, testData.get_elementInfo(5))
    btnResetCode_loc = (by.ID, testData.get_elementInfo(6))

    def input_ResetPasswordNewPassword(self, ResetPasswordNewPassword):
        """输入Reset Password New Password"""
        self.send_keys(ResetPasswordNewPassword, self.find_element(*self.etResetPasswordNewPassword_loc))

    def input_ResetPasswordNewPasswordCfm(self, ResetPasswordNewPasswordCfm):
        """输入Reset Password New Password confirm"""
        self.send_keys(ResetPasswordNewPasswordCfm, self.find_element(*self.etResetPasswordNewPasswordCfm_loc))

    def click_btnResetCode(self):
        """点击Reset password 的Next 按钮"""
        self.find_element(*self.btnResetCode_loc).click()

    def assertVisible_ResetCodenext(self):
        """判断 ResetCode 下的next 按钮是否存在"""
        return self.assertVisible(*self.btnResetCode_loc)
